Merge pull request #967 from TildeWill/intercept_dev_email

Intercept email in development

Andrew Cantino 8 anos atrás
pai
commit
d217b5ff70

+ 3 - 2
.env.example

@@ -57,7 +57,7 @@ SKIP_INVITATION_CODE=false
57 57
 # Outgoing email settings.  To use Gmail or Google Apps, put your Google Apps domain or gmail.com
58 58
 # as the SMTP_DOMAIN and your Gmail username and password as the SMTP_USER_NAME and SMTP_PASSWORD.
59 59
 #
60
-# PLEASE NOTE: In order to enable emails locally (e.g., when not in the production Rails environment),
60
+# PLEASE NOTE: In order to enable sending real emails via SMTP locally (e.g., when not in the production Rails environment),
61 61
 # you must also set SEND_EMAIL_IN_DEVELOPMENT to true below.
62 62
 #
63 63
 # If you have trouble with port 587 on Gmail, you can also try setting
@@ -71,7 +71,8 @@ SMTP_PORT=587
71 71
 SMTP_AUTHENTICATION=plain
72 72
 SMTP_ENABLE_STARTTLS_AUTO=true
73 73
 
74
-# Send emails when running in the development Rails environment.
74
+# Set to true to send real emails via SMTP when running in the development Rails environment.
75
+# Set to false to have emails intercepted in development and displayed at http://localhost:3000/letter_opener
75 76
 SEND_EMAIL_IN_DEVELOPMENT=false
76 77
 
77 78
 # The address from which system emails will appear to be sent.

+ 1 - 0
Gemfile

@@ -101,6 +101,7 @@ group :development do
101 101
   gem 'guard'
102 102
   gem 'guard-livereload'
103 103
   gem 'guard-rspec'
104
+  gem 'letter_opener_web'
104 105
 
105 106
   group :test do
106 107
     gem 'coveralls', require: false

+ 7 - 0
Gemfile.lock

@@ -234,6 +234,12 @@ GEM
234 234
     kramdown (1.3.3)
235 235
     launchy (2.4.2)
236 236
       addressable (~> 2.3)
237
+    letter_opener (1.4.1)
238
+      launchy (~> 2.2)
239
+    letter_opener_web (1.3.0)
240
+      actionmailer (>= 3.2)
241
+      letter_opener (~> 1.0)
242
+      railties (>= 3.2)
237 243
     libv8 (3.16.14.7)
238 244
     liquid (3.0.6)
239 245
     listen (2.7.9)
@@ -529,6 +535,7 @@ DEPENDENCIES
529 535
   jsonpath (~> 0.5.6)
530 536
   kaminari (~> 0.16.1)
531 537
   kramdown (~> 1.3.3)
538
+  letter_opener_web
532 539
   liquid (~> 3.0.3)
533 540
   mini_magick
534 541
   mqtt

+ 3 - 1
README.md

@@ -66,7 +66,9 @@ If you just want to play around, you can simply fork this repository, then perfo
66 66
 * Read the [wiki][wiki] for usage examples and to get started making new Agents.
67 67
 * Periodically run `git fetch upstream` and then `git checkout master && git merge upstream/master` to merge in the newest version of Huginn.
68 68
 
69
-Note: by default, emails are not sent in the `development` Rails environment, which is what you just setup.  If you'd like to enable emails when playing with Huginn locally, set `SEND_EMAIL_IN_DEVELOPMENT` to `true` in your `.env` file.
69
+Note: By default, emails are intercepted in the `development` Rails environment, which is what you just setup.  You can view 
70
+them at [http://localhost:3000/letter_opener](http://localhost:3000/letter_opener). If you'd like to send real emails via SMTP when playing 
71
+with Huginn locally, set `SEND_EMAIL_IN_DEVELOPMENT` to `true` in your `.env` file.
70 72
 
71 73
 If you need more detailed instructions, see the [Novice setup guide][novice-setup-guide].
72 74
 

+ 5 - 2
config/environments/development.rb

@@ -39,8 +39,11 @@ Huginn::Application.configure do
39 39
 
40 40
   config.action_mailer.default_url_options = { :host => ENV['DOMAIN'] }
41 41
   config.action_mailer.asset_host = ENV['DOMAIN']
42
-  config.action_mailer.perform_deliveries = ENV['SEND_EMAIL_IN_DEVELOPMENT'] == 'true'
43 42
   config.action_mailer.raise_delivery_errors = true
44
-  config.action_mailer.delivery_method = :smtp
43
+  if ENV['SEND_EMAIL_IN_DEVELOPMENT'] == 'true'
44
+    config.action_mailer.delivery_method = :smtp
45
+  else
46
+    config.action_mailer.delivery_method = :letter_opener_web
47
+  end
45 48
   # smtp_settings moved to config/initializers/action_mailer.rb
46 49
 end

+ 4 - 0
config/routes.rb

@@ -74,6 +74,10 @@ Huginn::Application.routes.draw do
74 74
   devise_for :users,
75 75
              controllers: { omniauth_callbacks: 'omniauth_callbacks' },
76 76
              sign_out_via: [:post, :delete]
77
+  
78
+  if Rails.env.development?
79
+    mount LetterOpenerWeb::Engine, at: "/letter_opener"
80
+  end
77 81
 
78 82
   get "/about" => "home#about"
79 83
   root :to => "home#index"

+ 3 - 2
deployment/site-cookbooks/huginn_production/files/default/env.example

@@ -49,7 +49,7 @@ SKIP_INVITATION_CODE=false
49 49
 # Outgoing email settings.  To use Gmail or Google Apps, put your Google Apps domain or gmail.com
50 50
 # as the SMTP_DOMAIN and your Gmail username and password as the SMTP_USER_NAME and SMTP_PASSWORD.
51 51
 # 
52
-# PLEASE NOTE: In order to enable emails locally (e.g., when not in the production Rails environment),
52
+# PLEASE NOTE: In order to enable sending real emails via SMTP locally (e.g., when not in the production Rails environment),
53 53
 # you must also set SEND_EMAIL_IN_DEVELOPMENT to true below.
54 54
 
55 55
 SMTP_DOMAIN=your-domain-here.com
@@ -60,7 +60,8 @@ SMTP_PORT=587
60 60
 SMTP_AUTHENTICATION=plain
61 61
 SMTP_ENABLE_STARTTLS_AUTO=true
62 62
 
63
-# Send emails when running in the development Rails environment.
63
+# Set to true to send real emails via SMTP when running in the development Rails environment.
64
+# Set to false to have emails intercepted in development and displayed at http://localhost:3000/letter_opener
64 65
 SEND_EMAIL_IN_DEVELOPMENT=false
65 66
 
66 67
 # The address from which system emails will appear to be sent.